package com.lglbc.client;

import com.lglbc.hello.Mode;
import com.lglbc.hello.OpenAPIGrpc;
import io.grpc.stub.StreamObserver;

public class Service extends OpenAPIGrpc.OpenAPIImplBase {

    @Override
    public StreamObserver<Mode.Request> clientStreaming(StreamObserver<Mode.Response> responseObserver) {
        return new StreamObserver<Mode.Request>() {
            @Override
            public void onNext(Mode.Request request) {
                // 处理接收到的请求
                System.out.println("收到客户端请求:"+request.getName());
            }

            @Override
            public void onError(Throwable t) {
                // 处理错误
                System.out.println("错误信息:"+t.getMessage());
            }

            @Override
            public void onCompleted() {
                // 发送响应
                Mode.Response response = Mode.Response.newBuilder()
                        .setMessage("消息处理完成")
                        .build();
                responseObserver.onNext(response);
                responseObserver.onCompleted();
            }
        };
    }
}
